
const {
	getPayInfo
} = require("@/utils/http")


const payUtil = {
	
//获取支付信息
getPayInfo: async function(params){
	
	
	let date = new Date().toLocaleString('zh-CN', { hour12: false }).replace(/[^\d]/g, '');
	console.log("date=======",date,params.jsHjJe);
	let json = {
		inst_no:'900221',
		mch_no:'852401110001',
		pay_type:'400',
		pay_trace_no:'',
		pay_time:date,
		total_amount:params.jsHjJe,
		open_id:uni.getStorageSync("userInfo").openid
	}
	
	const {
		code,
		data
	} = await getPayInfo(json)
	if (code == '0000') {
		
		this.payOrder(data);
		
	}
		
},
	

// 支付
payOrder:function(pay) {
	
	uni.requestPayment({
		appId: pay.appId,
		provider: "wxpay", //服务提供商
		timeStamp: pay.timeStamp, //时间戳
		nonceStr: pay.nonceStr, //随机字符串
		package: pay.packageValue, //统一下单接口返回的 prepay_id 参数值，提交格式如：prepay_id=xx
		signType: pay.signType, //签名算法
		paySign: pay.paySign, //签名
		// 支付成功的回调
		success(result) {
			if (result.errMsg == "requestPayment:ok") {
				console.log("支付成功")
				//跳转到支付状态页面（成功页面）
				uni.navigateTo({
					url: `/pages/order/payState`
				})
			}
		},
		// 支付失败回调
		fail(err) {
			console.log("支付失败")
			
			//跳转到支付状态页面（失败页面）
			uni.navigateTo({
				url: `/pages/order/payState`
			})
			
		}
		
	})

},




}

module.exports = payUtil;